package no.uib.hplims.jobs;

import java.util.ArrayList;
import java.util.List;

import uk.ac.ebi.kraken.interfaces.uniprot.UniProtEntry;
import uk.ac.ebi.kraken.uuw.services.remoting.EntryIterator;
import uk.ac.ebi.kraken.uuw.services.remoting.Query;
import uk.ac.ebi.kraken.uuw.services.remoting.UniProtJAPI;
import uk.ac.ebi.kraken.uuw.services.remoting.UniProtQueryBuilder;
import uk.ac.ebi.kraken.uuw.services.remoting.UniProtQueryService;

public class UniProtQueryTool {
	
	public UniProtQueryTool() {
	}

	/**
	 * Looks up a list of UniProt accession numbers to find the proteins' 
	 * sequence and returns a list of sequences.
	 * 
	 * @param accList List of accession numbers (both primary and secondary
	 * 				are acceptable, as well as Isoform IDs and entry IDs)
	 * @return List of protein sequences
	 */
	public static List<String> findSequencesByUniProtAccessionNumbers(List<String> accList) {
		// Create UniProt query service
	    UniProtQueryService uniProtQueryService = UniProtJAPI.factory.getUniProtQueryService();

	    Query query = UniProtQueryBuilder.buildIDListQuery(accList);

	    ArrayList<String> sequences = new ArrayList<String>();
	    EntryIterator<UniProtEntry> entries = uniProtQueryService.getEntryIterator(query);
	    for (UniProtEntry entry : entries) {
	    	sequences.add(entry.getSequence().getValue());
	    }
	    return sequences;
	}
}
